Cf.Component = Cf.Class({
	constructor: function(config){
		Cf.put(this, config);
		
		if(this.listeners){
			var l;
			for(var i in this.listeners){
				l = this.listeners[i];
				if(Cf.isFunction(l)){
					this.addListener(i, l);
				}else{
					this.addListener(i, l.fn, l.scope);
				}
			}
		}
		
		if(this.plugins){
			var p;
			for(var i = 0; i < this.plugins.length; ++i){
				p = Cf.isFunction(this.plugins[i])? new this.plugins[i](this) : this.plugins[i];
				p.init(this);
			}
		}
	}

	,addEvents: function(/*arguments*/){
		var me = this
			,e;
		me.__events = me.__events || {};
		
		for(var i = 0, len = arguments.length; i < len; ++i){
			e = arguments[i];
			if(!Cf.isUndefined(me.__events[e])) continue;
			
			me.__events[e] = [];
			me['on' + e.ucfirst()] = (function(fn, scope){
				me.addListener(this, fn, scope);
			}).bind(e);
			
			me['un' + e.ucfirst()] = (function(fn, scope){
				me.removeListener(this, fn, scope);
			}).bind(e);
		}
	}
	
	,fireEvent: function(/*arguments*/){
		var name = [].splice.call(arguments, 0, 1);
		if(!this.__events[name]) return;
		
		for(var i = 0; i < this.__events[name].length; ++i){
			var e = this.__events[name][i];
			
			// if one of callback return Cf.V_HALT
			// stop execute event and return Cf.V_HALT
			if(Cf.V_HALT === e.fn.apply(e.scope, arguments)) return Cf.V_HALT;
		}
		return true;
	}
	
	,addListener: function(name, fn, scope){
		if(Cf.isUndefined(this.__events[name])) return this;
		
		this.__events[name].push({
			fn: fn
			,scope: scope
		});
		
		return this;
	}
	
	,removeListener: function(name, fn, scope){
		if(Cf.isUndefined(this.__events[name])) return this;
		
		var e;
		for(var i = 0; i < this.__events[name].length; ++i){
			e = this.__events[name][i];
			if(e.fn === fn && e.scope === scope) this.__events[name].splice(i, 1);
		}
		
		return this;
	}
});